<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="javax.jdo.Query" %>
<%@ page import="com.bufbomb.datastore.*" %>
<%@ page import="com.google.appengine.api.users.*" %>

<html>
  <body>
	<center>
	<h1>Flash游戏仓库</h1>
<%
	PersistenceManager pm = PMF.get().getPersistenceManager();
try
{
	Query query = pm.newQuery(FlashItem.class);
	query.setOrdering("uploadDate desc");
	List<FlashItem> records = (List<FlashItem>) query.execute(); 
	if (records.isEmpty()) {
%>
<h3>Empty records</h3>
<%
	}
	else
	{
%>
<table border="1">
<tr>
<td width="300">名称</td><td>简介</td><td>上传时间</td>
</tr>
<%
	for(FlashItem si : records)
		{
%>
<tr>
<td><a href='flash.jsp?id=<%=si.getId()%>' ><%=si.getName() %></a></td>
<td><%=si.getDescription() %></td>
<td><%=si.getDate() %></td>
</tr>
<%	
		}
		//resp.setContentType(su.getContentType());
		//resp.getOutputStream().write(su.getBlob().getBytes());
	}
%>
</table>
<%
}
finally
{
	pm.close();
}
%>
<%
%>
	</center>
	<hr />
	<center>
<%
UserService userService = UserServiceFactory.getUserService();
if (!userService.isUserLoggedIn()) 
{
%>
<a href="/login">Sign In</a> 
<%
}
else
{	
	if(userService.isUserAdmin())
	{
%>
<a href="/hiddenupload.html">Upload</a>
<%
	}
%>
<a href='<%=userService.createLogoutURL("/index.jsp") %>'> Sign Out </a>
<%
}
%>
</center>
	<center>
	<span class="copyright">&copy;2010 bufbomb.com</span>
	</center>
  </body>
</html>
